#!/usr/bin/env python
#_*_ coding:utf-8 _*_
from django.shortcuts import render, render_to_response
from app05 import models, common, html_helper

# Create your views here.
def index(request,page):
    #操作数据库进行分页
    print page, type(page)
    per_item1 = request.COOKIES.get('pager_num',10)
    per_item=common.try_int(request.COOKIES.get('pager_num',10), 10)
    page=common.try_int(page, 1);
        
    #print page, type(page)
    
    result = models.Host.objects.all()
    count=result.count()
    
    pageInfo = html_helper.PageInfo(page,count, per_item)
    #start=pageInfo.start()
    #end=pageInfo.end()
    #all_page_count=pageInfo.all_page_count()
    
    result=result[pageInfo.start:pageInfo.end]
    page_str=html_helper.pager(page, pageInfo.all_page_count)
    ret={'data':result,'count':count,'page':page_str}
    
    
    response = render_to_response('app05/index.html',ret)
    #response.set_cookie('pager_num',per_item)
    return response